package com.bosssoft.hr.javase;

import java.io.File;
import java.io.IOException;

/**
 * @Description: HttpFileDownloader
 * @Author: wengyu
 * @CreateTime: 2022/05/13 15:53
 */
public class HttpFileDownloader {

    private static final String FILE_PATH = "user.xml";

    private static final int CORE_POOL_SIZE = 5;
    private static final int MAX_POOL_SIZE = 5;


    /**
     * 下载文件
     *
     * @param url 请求路径
     * @return 是否下载成功 成功返回true 失败返回 false
     */
    public Boolean download(String url) {
        try {
            File file = new File(FILE_PATH);
            if (!file.exists()) {
                DownloadFileThreadPool downloadFileThreadPool = new DownloadFileThreadPool();
                downloadFileThreadPool.getFileWithThreadPool(url, FILE_PATH, CORE_POOL_SIZE, MAX_POOL_SIZE);
            }
            return true;
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
